'\" t
.\"     Title: pg_resetwal
.\"    Author: The PostgreSQL Global Development Group
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\"      Date: 2021
.\"    Manual: PostgreSQL 13.3 Documentation
.\"    Source: PostgreSQL 13.3
.\"  Language: English
.\"
.TH "PG_RESETWAL" "1" "2021" "PostgreSQL 13.3" "PostgreSQL 13.3 Documentation"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
pg_resetwal \- reset the write\-ahead log and other control information of a PostgreSQL database cluster
.SH "SYNOPSIS"
.HP \w'\fBpg_resetwal\fR\ 'u
\fBpg_resetwal\fR [\fB\-f\fR | \fB\-\-force\fR] [\fB\-n\fR | \fB\-\-dry\-run\fR] [\fIoption\fR...] [\fB\-D\fR | \fB\-\-pgdata\fR]\fIdatadir\fR
.SH "DESCRIPTION"
.PP
\fBpg_resetwal\fR
clears the write\-ahead log (WAL) and optionally resets some other control information stored in the
pg_control
file\&. This function is sometimes needed if these files have become corrupted\&. It should be used only as a last resort, when the server will not start due to such corruption\&.
.PP
After running this command, it should be possible to start the server, but bear in mind that the database might contain inconsistent data due to partially\-committed transactions\&. You should immediately dump your data, run
\fBinitdb\fR, and reload\&. After reload, check for inconsistencies and repair as needed\&.
.PP
This utility can only be run by the user who installed the server, because it requires read/write access to the data directory\&. For safety reasons, you must specify the data directory on the command line\&.
\fBpg_resetwal\fR
does not use the environment variable
\fBPGDATA\fR\&.
.PP
If
\fBpg_resetwal\fR
complains that it cannot determine valid data for
pg_control, you can force it to proceed anyway by specifying the
\fB\-f\fR
(force) option\&. In this case plausible values will be substituted for the missing data\&. Most of the fields can be expected to match, but manual assistance might be needed for the next OID, next transaction ID and epoch, next multitransaction ID and offset, and WAL starting location fields\&. These fields can be set using the options discussed below\&. If you are not able to determine correct values for all these fields,
\fB\-f\fR
can still be used, but the recovered database must be treated with even more suspicion than usual: an immediate dump and reload is imperative\&.
\fIDo not\fR
execute any data\-modifying operations in the database before you dump, as any such action is likely to make the corruption worse\&.
.SH "OPTIONS"
.PP
\fB\-f\fR
.br
\fB\-\-force\fR
.RS 4
Force
\fBpg_resetwal\fR
to proceed even if it cannot determine valid data for
pg_control, as explained above\&.
.RE
.PP
\fB\-n\fR
.br
\fB\-\-dry\-run\fR
.RS 4
The
\fB\-n\fR/\fB\-\-dry\-run\fR
option instructs
\fBpg_resetwal\fR
to print the values reconstructed from
pg_control
and values about to be changed, and then exit without modifying anything\&. This is mainly a debugging tool, but can be useful as a sanity check before allowing
\fBpg_resetwal\fR
to proceed for real\&.
.RE
.PP
\fB\-V\fR
.br
\fB\-\-version\fR
.RS 4
Display version information, then exit\&.
.RE
.PP
\fB\-?\fR
.br
\fB\-\-help\fR
.RS 4
Show help, then exit\&.
.RE
.PP
The following options are only needed when
\fBpg_resetwal\fR
is unable to determine appropriate values by reading
pg_control\&. Safe values can be determined as described below\&. For values that take numeric arguments, hexadecimal values can be specified by using the prefix
0x\&.
.PP
\fB\-c \fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
.br
\fB\-\-commit\-timestamp\-ids=\fR\fB\fIxid\fR\fR\fB,\fR\fB\fIxid\fR\fR
.RS 4
Manually set the oldest and newest transaction IDs for which the commit time can be retrieved\&.
.sp
A safe value for the oldest transaction ID for which the commit time can be retrieved (first part) can be determined by looking for the numerically smallest file name in the directory
pg_commit_ts
under the data directory\&. Conversely, a safe value for the newest transaction ID for which the commit time can be retrieved (second part) can be determined by looking for the numerically greatest file name in the same directory\&. The file names are in hexadecimal\&.
.RE
.PP
\fB\-e \fR\fB\fIxid_epoch\fR\fR
.br
\fB\-\-epoch=\fR\fB\fIxid_epoch\fR\fR
.RS 4
Manually set the next transaction ID\*(Aqs epoch\&.
.sp
The transaction ID epoch is not actually stored anywhere in the database except in the field that is set by
\fBpg_resetwal\fR, so any value will work so far as the database itself is concerned\&. You might need to adjust this value to ensure that replication systems such as
Slony\-I
and
Skytools
work correctly \(em if so, an appropriate value should be obtainable from the state of the downstream replicated database\&.
.RE
.PP
\fB\-l \fR\fB\fIwalfile\fR\fR
.br
\fB\-\-next\-wal\-file=\fR\fB\fIwalfile\fR\fR
.RS 4
Manually set the WAL starting location by specifying the name of the next WAL segment file\&.
.sp
The name of next WAL segment file should be larger than any WAL segment file name currently existing in the directory
pg_wal
under the data directory\&. These names are also in hexadecimal and have three parts\&. The first part is the
\(lqtimeline ID\(rq
and should usually be kept the same\&. For example, if
00000001000000320000004A
is the largest entry in
pg_wal, use
\-l 00000001000000320000004B
or higher\&.
.sp
Note that when using nondefault WAL segment sizes, the numbers in the WAL file names are different from the LSNs that are reported by system functions and system views\&. This option takes a WAL file name, not an LSN\&.
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBNote\fR
.ps -1
.br
\fBpg_resetwal\fR
itself looks at the files in
pg_wal
and chooses a default
\fB\-l\fR
setting beyond the last existing file name\&. Therefore, manual adjustment of
\fB\-l\fR
should only be needed if you are aware of WAL segment files that are not currently present in
pg_wal, such as entries in an offline archive; or if the contents of
pg_wal
have been lost entirely\&.
.sp .5v
.RE
.RE
.PP
\fB\-m \fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
.br
\fB\-\-multixact\-ids=\fR\fB\fImxid\fR\fR\fB,\fR\fB\fImxid\fR\fR
.RS 4
Manually set the next and oldest multitransaction ID\&.
.sp
A safe value for the next multitransaction ID (first part) can be determined by looking for the numerically largest file name in the directory
pg_multixact/offsets
under the data directory, adding one, and then multiplying by 65536 (0x10000)\&. Conversely, a safe value for the oldest multitransaction ID (second part of
\fB\-m\fR) can be determined by looking for the numerically smallest file name in the same directory and multiplying by 65536\&. The file names are in hexadecimal, so the easiest way to do this is to specify the option value in hexadecimal and append four zeroes\&.
.RE
.PP
\fB\-o \fR\fB\fIoid\fR\fR
.br
\fB\-\-next\-oid=\fR\fB\fIoid\fR\fR
.RS 4
Manually set the next OID\&.
.sp
There is no comparably easy way to determine a next OID that\*(Aqs beyond the largest one in the database, but fortunately it is not critical to get the next\-OID setting right\&.
.RE
.PP
\fB\-O \fR\fB\fImxoff\fR\fR
.br
\fB\-\-multixact\-offset=\fR\fB\fImxoff\fR\fR
.RS 4
Manually set the next multitransaction offset\&.
.sp
A safe value can be determined by looking for the numerically largest file name in the directory
pg_multixact/members
under the data directory, adding one, and then multiplying by 52352 (0xCC80)\&. The file names are in hexadecimal\&. There is no simple recipe such as the ones for other options of appending zeroes\&.
.RE
.PP
\fB\-\-wal\-segsize=\fR\fB\fIwal_segment_size\fR\fR
.RS 4
Set the new WAL segment size, in megabytes\&. The value must be set to a power of 2 between 1 and 1024 (megabytes)\&. See the same option of
\fBinitdb\fR(1)
for more information\&.
.if n \{\
.sp
.\}
.RS 4
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.ps +1
\fBNote\fR
.ps -1
.br
While
\fBpg_resetwal\fR
will set the WAL starting address beyond the latest existing WAL segment file, some segment size changes can cause previous WAL file names to be reused\&. It is recommended to use
\fB\-l\fR
together with this option to manually set the WAL starting address if WAL file name overlap will cause problems with your archiving strategy\&.
.sp .5v
.RE
.RE
.PP
\fB\-x \fR\fB\fIxid\fR\fR
.br
\fB\-\-next\-transaction\-id=\fR\fB\fIxid\fR\fR
.RS 4
Manually set the next transaction ID\&.
.sp
A safe value can be determined by looking for the numerically largest file name in the directory
pg_xact
under the data directory, adding one, and then multiplying by 1048576 (0x100000)\&. Note that the file names are in hexadecimal\&. It is usually easiest to specify the option value in hexadecimal too\&. For example, if
0011
is the largest entry in
pg_xact,
\-x 0x1200000
will work (five trailing zeroes provide the proper multiplier)\&.
.RE
.SH "ENVIRONMENT"
.PP
\fBPG_COLOR\fR
.RS 4
Specifies whether to use color in diagnostic messages\&. Possible values are
always,
auto
and
never\&.
.RE
.SH "NOTES"
.PP
This command must not be used when the server is running\&.
\fBpg_resetwal\fR
will refuse to start up if it finds a server lock file in the data directory\&. If the server crashed then a lock file might have been left behind; in that case you can remove the lock file to allow
\fBpg_resetwal\fR
to run\&. But before you do so, make doubly certain that there is no server process still alive\&.
.PP
\fBpg_resetwal\fR
works only with servers of the same major version\&.
.SH "SEE ALSO"
\fBpg_controldata\fR(1)
